<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改网页文件管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-filemanage-edit" th:object="${websiteFileManage}">
            <input name="websiteManageId" th:field="*{websiteManageId}" type="hidden" id="websiteManageId">
            <input name="websiteManageSrc" th:field="*{websiteManageSrc}" class="form-control" type="hidden" id="websiteManageSrc">
            <div class="form-group">
                <label class="col-sm-3 control-label">文件上传：</label>
                <div class="col-sm-8">
                    <input id="file" type="file" class="form-control">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
        var prefix = ctx + "websitefilemanage/filemanage";
        $("#form-filemanage-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                let formData = new FormData();
                formData.append("file", $("#file")[0].files[0]);
                //文件源路径，删除使用
                formData.append("websiteManageSrc",$("#websiteManageSrc").val());
                formData.append("websiteManageId",$("#websiteManageId").val());
                $.ajax({
                    type: 'post',
                    url: prefix + '/edit',
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    dataType: 'json',
                    success: function (result) {
                        if (result.code == 0) {
                            $.modal.msgReload(result.msg, "success");
                        } else {
                            $.modal.msgReload(result.msg, "error");
                        }
                    },
                    error: function (error) {
                        $.modal.alertWarning("添加失败");
                    }
                })
            }
        }

        $(function () {
            //初始化文件上传插件
            $("#file").fileinput({
                'theme': 'explorer-fas',
                enctype: 'multipart/form-data',
                language: 'zh',
                overwriteInitial: false,
                initialPreviewAsData: true,
                contentType: false,
                showUpload: false,
                showBrowse: true,
                showPreview: true,
                showRemove: true,
                showCancel:true,
                previewFileType:['html', 'text', 'video', 'audio', 'flash', 'object'],
                //initialPreview: ctx + $("#newsPhoto").val(), //回显内容
                dropZoneTitle: "文件上传，上传后可通过链接直接下载或查看",
            });
        })
    </script>
</body>
</html>